//
//  VIZCellViewModel.swift
//  VIZ微博
//
//  Created by 位立志 on 16/4/13.
//  Copyright © 2016年 位立志. All rights reserved.
//

import UIKit

class VIZCellViewModel: NSObject {

    //cell的model
    var homeStatuse : VIZHomeStatuse?
    //
    var mbImage: UIImage?
    //认证图片类型
    var headImageURL: NSURL?
    //转发
    var response : String?
    //评论
    var message : String?
    //赞
    var well : String?
    //正文

    
    var verifiedImage: UIImage?

    init(homeStatuse:VIZHomeStatuse) {
        super.init()
        self.homeStatuse = homeStatuse
        
        headImageURL = NSURL(string: homeStatuse.user?.profile_image_url ?? "")
        
        //用户等级
        dealmbRank()
        //用户的认证类型
        dealVerifiedType()
        //微博正文
//        text = homeStatuse.text
        
        //工具条赋值
        response = self.setToolBarStr(homeStatuse.reposts_count, name: "转发")
        message = self.setToolBarStr(homeStatuse.comments_count, name: "评论")
        well = self.setToolBarStr(homeStatuse.attitudes_count, name: "赞")
        
    }
    
    private func setToolBarStr(count:Int, name:String)->(String){
        
        if count<=0 {
            return name
        }
        if count >= 1000{
            return "\(count/10000)"
        }
        
        return "\(count)"
        
    }
    
    
    
    
}

//处理逻辑
extension VIZCellViewModel {
    
    private func dealmbRank() {
        let mbType = homeStatuse?.user?.mbrank ?? 0
        if mbType > 0 && mbType < 7 {
            mbImage = UIImage(named: "common_icon_membership_level\(mbType)")
        }
    }
    
    private func dealVerifiedType() {
        //用户认证类型
        let verifiedType = homeStatuse?.user?.verified_type ?? -1
        switch verifiedType {
        case 1:
            verifiedImage = UIImage(named: "avatar_vip")
        case 2,3,5:
            verifiedImage = UIImage(named: "avatar_enterprise_vip")
        case 220:
            verifiedImage = UIImage(named: "avatar_grassroot")
        default:
            verifiedImage = nil
        }
        
    }


    
}





